using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.MonoRail.ActiveRecordSupport;
using Castle.MonoRail.Framework;
using ElevatorSpeeches.Framework;

namespace ElevatorSpeeches.Controllers
{
    [Layout("default"), Rescue("generalerror")]
    public class SpeechTopicController : BaseController
    {

        public void Display(string prettyUrl)
        {
            PropertyBag["SpeechTopic"] = SpeechTopic.FindByPrettyUrl(prettyUrl);
			
        }

        public void Create()
        {         
        }

        public void Save(string title, string nouns)
        {
            SpeechTopic topic = SpeechTopic.Create(title);
            foreach (string nounBody in nouns.Split(','))
            {
                topic.Nouns.Add(Noun.GetOrCreate(nounBody));
                
            }
            topic.Save();
            
            RedirectToAction("display", "prettyUrl=" + topic.PrettyUrl);
        }


    }
}
